package com.example.orderassembly.controller;


import com.example.orderassembly.service.IStorePurchaseDetailOrderService;
import com.woniu.cloud.common.exception.TicketException;
import com.woniuxy.api.StorePurchaseDetailOrderApi;
import com.woniu.cloud.common.dto.Result;
import com.woniuxy.entity.StorePurchaseDetailOrder;
import com.woniuxy.form.GetOrder;
import com.woniuxy.form.InsertStorePurchaseDetailOrder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 店铺进货订单详情表 前端控制器
 * </p>
 *
 * @author yang
 * @since 2021-09-21
 */
@RestController
@Slf4j
@SuppressWarnings("all")
public class StorePurchaseDetailOrderController implements StorePurchaseDetailOrderApi {
    @Resource
    IStorePurchaseDetailOrderService iStorePurchaseDetailOrderService;

    /**
     * 已测
     * @param insertStorePurchaseDetailOrder
     * @return
     */
    @PostMapping("/insertStorePurchaseDetailOrder")
    @Override
    public Result insertStorePurchaseDetailOrder(InsertStorePurchaseDetailOrder insertStorePurchaseDetailOrder) {
        log.info("增加店铺进货订单详情 参数 insertStorePurchaseDetailOrder={}",insertStorePurchaseDetailOrder);
        if(insertStorePurchaseDetailOrder==null){
            log.info("参数错误");
            throw  new TicketException("参数异常");
        }
        Boolean bool = iStorePurchaseDetailOrderService.insertStorePurchaseDetailOrder(insertStorePurchaseDetailOrder);
        return bool?Result.success("下单成功",bool):Result.fail("下单失败",bool);
    }


    /**
     * 已测
     * @param orderId
     * @return
     */
    @Override
    public Result getStorePurchaseDetailOrderByStorePurchaseOrderId(Integer orderId) {
        log.info("根据进货订单查询对应的进货详情 参数 orderId={}",orderId);
        if (null==orderId){
            log.info("参数错误");
            throw  new TicketException("参数异常");
        }
        List<StorePurchaseDetailOrder> list = iStorePurchaseDetailOrderService.getStorePurchaseDetailOrderByStorePurchaseOrderId(orderId);
        return list.size()==0?Result.fail("查询失败",false):Result.success("查询成功",list);
    }


    //不需要的接口
    @Override
    public Result getStorePurchaseDetailOrderByStore(Integer storeId, Integer indexPage) {
        return null;
    }
}

